<?php
/**
 * Created by PhpStorm.
 * User: yuan
 * Date: 18-8-23
 * Time: 上午11:20
 */

function isPost() {
    return ($_SERVER['REQUEST_METHOD'] == 'POST');
}


$url = trim($_POST['url']);
$method = trim($_POST['method']);
$params = [];
if ($_POST['params']) {
    $params = json_decode(trim($_POST['params']));
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $method == 'post' ? 1 : 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_ENCODING, ""); //必须解压缩防止乱码
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; zh-CN) AppleWebKit/535.12 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/535.12");
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

$output = curl_exec($ch);
curl_close($ch);
echo $output;